-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try to make virtualenv metadata findable when invoked globally #207
Conversation
Nice work, this seems to be a very good solution approach. I ran some tests locally and it seems to find the metadata in the virtual environment in all cases! I will need some time to look into your proposed changes and see if I can provide some feedback, I will start now but will probably have to continue later this weekend. The first thing I notice is the following:
Here, I installed deptry globally. This error does not seem appropriate; I already activated my environment. Maybe we can try and detect the difference between a non-activated virtual environment, and a globally installed deptry version? |
Need to sign off for now since my train just arrived at the station, but just wanted to let you know I am impressed with your work! I hope I did not discourage you with my feedback. I look forward to merging this after one or two iterations :) |
Thanks for your very kind and spot-on feedback :) I made an iteration during the limited time I had this morning, factoring out the logic in a dedicated Regarding your main comment concerning the warning message you were totally right: the issue is not whether the project virtualenv is active or not, but rather if we are being run by its interpreter. Have a nice day :) |
I'm not very knowledgeable with - repo: https://github.com/fpgmaas/deptry.git
rev: <tag>
hooks:
- id: deptry
args:
- "--skip-missing"
- "--project-virtualenv path/to/virtualenv" But that might be something for another PR :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I think it's a nice option to be able to run deptry from a global installation, I must say I'm not a fan of the part that dynamically tries to guess where the virtual environment is, as the location is not standard, so the virtual environment can be created in various locations depending on the tool used.
For instance:
- Poetry will by default create them in
~/.cache/pypoetry/virtualenvs
on Linux - pyenv-virtualenv will by default create them in
~/.pyenv/versions
on Linux
A more flexible choice might be to add a custom option to define the path to the virtual environment, like virtual-environment-path
, since this would made the logic more simple and less magical, while allowing the flexibility that some users might need.
|
Thanks for your remarks @mkniewallner. I do agree that the guessing is brittle. One could argue that failing to find the virtualenv (because the candidate location list is incomplete) leaves the user no worse off than before. But maybe more worrisome is the risk to wrongly guess a virtualenv... So @fpgmaas do you think should I directly work in this PR to add |
@kwentine Yes, I think @mkniewallner point's are valid and his suggestion is a good one. Thanks mathieu for sharing your feedback! So then it would make sense to add the |
e04f180
to
4bc56ea
Compare
Co-authored-by: Florian Maas <[email protected]>
4bc56ea
to
3c7a727
Compare
Hi 👋🏻 Had shot at supporting |
I also wanted to share an alternative, more explicit way of searching for metadata in a custom path, that occurred to me while perusing from importlib.metadata import Distribution
def distribution(name: str, path: str | None):
kwargs = {'name': name}
if path is not None:
kwargs['path'] = [path] # or `[path, *sys.path]` ?
try:
return next(Distribution.discover(**kwargs))
except StopIteration:
raise PackageNotFoundError(name) Using this function instead of |
I think since we explicitly looking for |
Co-authored-by: Florian Maas <[email protected]>
Co-authored-by: Florian Maas <[email protected]>
|
||
|
||
def install_metadata_finder(site_packages: Path) -> None: | ||
"""Add poject virtualenv site packages to metadata search path""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in project
Closing due to inactivity. |
PR Checklist
docs
is updatedDescription of changes
This PR is an attempt to fix #92 by:
deptry
is likely run outside of the project's virtualenvsite-packages
by checking common locations, and make it findable byimportlib.metadata
To test the changes on the
deptry
project itself: